﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Windows.Forms;

namespace Util
{
    /// <summary>
    /// Classe utilitária para gerar scripts javascript rotineiros  como 
    /// Message Box por exemplo.
    /// </summary>
    public class MSGBox
    {

        public static void ShowMessageBox(Page page, String message)
        {
            page.ClientScript.RegisterStartupScript(
                                                    typeof(String),
                                                    Guid.NewGuid().ToString(),
                                                    "alert('" + message + "');",
                                                    true);

        }

        public static void ShowMessageBoxRedirect(Page page, String message, String UrlToRedirect)
        {
            page.ClientScript.RegisterStartupScript(
                                                    typeof(String),
                                                    Guid.NewGuid().ToString(),
                                                    "alert('" + message + "');window.location.href='" + UrlToRedirect + "';",
                                                    true);

        }

        public static void ShowMessageBoxConfirm(Page page, String message)
        {
            page.ClientScript.RegisterStartupScript(
                                                    typeof(String),
                                                    Guid.NewGuid().ToString(),
                                                    "if(confirm('" + message + "')) " +
                                                    "  { " +

                                                    "  } " +
                                                    "else{ " +
                                                    "        window.location.reload(history.go(-1)); " +
                                                    "    }", true);

        }

        public static void ShowMessageBoxConfirmVoltar3p(Page page, String message)
        {
            page.ClientScript.RegisterStartupScript(
                                                    typeof(String),
                                                    Guid.NewGuid().ToString(),
                                                    "if(confirm('" + message + "')) " +
                                                    "  { " +
                                                            "history.go(-2); " +
                                                    "  } " +
                                                    "else{ " +

                                                    "    }", true);

        }

        public static void ShowMessageBoxConfirmRedirect(Page page, String message, String urltoredirect)
        {
            page.ClientScript.RegisterStartupScript(
                                                    typeof(String),
                                                    Guid.NewGuid().ToString(),
                                                    "if(confirm('" + message + "')) " +
                                                    "  { " +

                                                    "  } " +
                                                    "else{ " +
                                                    "        window.location.href='" + urltoredirect + "'; " +
                                                    "    }", true);

        }

        public static String decisao(String mensagem)
        {
            String x = MessageBox.Show(mensagem, "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1).ToString();

            return x;
        }
    }
}